package com.vjwealth.android.nos.activity.rescue_list

import com.android.volley.Request
import com.android.volley.Response
import com.google.gson.Gson
import com.vjwealth.android.nos.entity.RescueListEntity
import com.vjwealth.android.nos.http.Api
import com.vjwealth.android.nos.http.BaseStringRequest
import com.vjwealth.android.nos.http.VolleyUtils
import com.vjwealth.android.nos.utils.ParamsUtils

/**
 * projectName KNOS
 * date 2017/9/30
 * description com.vjwealth.android.nos.activity.rescue_list
 */
class RescueListPresenter(view: RescueListContract.View) : RescueListContract.Presenter {

    val mActivity: RescueListActivity
    val mRescueView: RescueListContract.View

    init {
        mActivity = view as RescueListActivity
        mRescueView = view
    }

    override fun fetchRescueList(customerId: String) {
        var map = ParamsUtils.p_map2string(hashMapOf("customerId" to customerId))
        var request = BaseStringRequest(Request.Method.POST, Api.car_rescue_list, map,
                Response.Listener { response ->
                    var rescueListEntity = Gson().fromJson(response.toString(), RescueListEntity::class.java)
                    if(rescueListEntity.meta.success){
                        mRescueView.showRescueList(rescueListEntity.data)
                    }else{
                        mRescueView.showExceptionMessage(rescueListEntity.meta.message)
                    }
                },
                Response.ErrorListener {  })
        VolleyUtils.requestQueue.add(request)
        VolleyUtils.requestQueue.start()
    }
}